<script>
	let platform
	// #ifdef MP-WEIXIN
	platform = 1
	// #endif
	// #ifdef MP-TOUTIAO
	platform = 2
	// #endif
	// #ifdef MP-KUAISHOU
	platform = 3
	// #endif
	// #ifdef H5
	platform = 4
	// #endif
	export default {
		onLaunch: function() {
			let version = "1.0.0"
			let oldVersion = uni.getStorageSync('version') || ''
			if (version != oldVersion) {
				uni.removeStorageSync('chat')
				uni.setStorageSync('version', version)
			}
			uni.hideTabBar();
			this.getTabbar();
			//判断账号登录 或者是微信登录
			// this.getLoginConfig();
			this.getRobot();
			this.getAd();
			this.getModelList()
			this.getAppList()
			this.getCode()
		},
		onLoad(e) {
			console.log(e);
		},
		methods: {
			//获取是否有邀请码进来
			getCode() {
				
			},
			// 获取底部tabbar
			async getTabbar() {
				const {data} = await uni.$u.http.get("/busi/tabbar/list");
				let choseArrList = []
				if (data.rows) {
					let choseArr = data.rows
					for (let i = 0; i < choseArr.length - 1; i++) {
						let minIndex = i;
						for (let j = i + 1; j < choseArr.length; j++) {
							if (choseArr[j].orderNum < choseArr[minIndex].orderNum) {
								minIndex = j;
							}
						}
						[choseArr[i], choseArr[minIndex]] = [choseArr[minIndex], choseArr[i]]
					}
					choseArrList = choseArr
				}
				this.$store.commit('setTabbar', choseArrList)
				// uni.switchTab({url: data.rows[0].pagePath})
			},
			async getLoginConfig() {
				const {data} = await uni.$u.http.get("/app/application/info/loginConfig");
				uni.setStorageSync("loginConfig", data.data);
			},
			// 获取机器人配置 是对话的头像的配置 和标题的配置
			async getRobot() {
				// const {data} = await uni.$u.http.get("app/robot/info/info", {params: {id: 1}});
				// this.$store.commit('setRobot', data.data)
			},
			// 获取广告
			async getAd() {
				const {data} = await uni.$u.http.get("/busi/adinfo/list");
				data.rows.forEach(item => {
					item.desc = item.desc?.replace(/\<p\>&lt;ad(.*?)&gt;&lt;\/ad&gt;\<\/p\>/g, '<ad$1></ad>');
				})
				uni.setStorageSync("ad", data.rows?.filter(item => item.platform === platform || item.platform ===0) || []);
			},
			// 获取模型
			async getModelList() {
				const {data} = await uni.$u.http.get('/busi/rolemodel/list?pageNum=1&pageSize=10')
				this.$store.commit('setModelList', data.rows)
				
			},
			// 获取应用信息
			async getAppList() {
				const {data} = await uni.$u.http.get('/aiv/aiApp/list')
				this.$store.commit('setAppList', data.rows)
				if (!this.$store.state.model.id) {
					data.rows[0].name = data.rows[0].appName
					data.rows[0].img = data.rows[0].appImg
					this.$store.commit('setModel', data.rows[0] || {})
				}
			}
		}
	};
</script>
<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	@import "style/common.scss";
	@import "style/theme.scss";
	@import 'colorui/main.css';
	@import 'colorui/icon.css';
	/*#ifndef MP*/
	@import url('https://at.alicdn.com/t/font_1681579_yaiyfblc2xt.css');
	/*#endif*/
	page {height: 100%;font-size: 28rpx;font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;}
</style>